<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>

<table>
    <tr>
        <td class="menucon">
            <html:link action="/product_getproducts.do" title="Go to main.">Products</html:link>
        </td>
    </tr>
</table>
<html:messages id="messages" property="customMessage" message="true">
    <div class="heading4"><bean:write name="messages"/></div>
</html:messages>
<html:errors/>
<html:messages id="messages" property="message" message="true">
    <ul>
        <li><bean:write name="messages"/></li>
    </ul>
</html:messages>
<table border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            <table cellspacing="0">
                <tr>
                    <td>Code</td>
                    <td>:</td>
                    <td>${prod.kode}</td>
                </tr>
                <tr>
                    <td>Name</td>
                    <td>:</td>
                    <td>${prod.nama}</td>
                </tr>
                <tr>
                    <td>Weight</td>
                    <td>:</td>
                    <td><f:formatNumber type="number" value="${prod.weight}" minFractionDigits="2"/> ${prod.hargaHpp.unit.nama}</td>
                </tr>
                <tr>
                    <td>Type</td>
                    <td>:</td>
                    <td>${prod.hargaHpp.jenis.nama}</td>
                </tr>
                <tr>
                    <td>StockLI</td>
                    <td>:</td>
                    <td><f:formatNumber type="number" value="${prod.stockLI}" maxFractionDigits="0"/></td>
                </tr>
                <tr>
                    <td>StockLE</td>
                    <td>:</td>
                    <td><f:formatNumber type="number" value="${prod.stockLE}" maxFractionDigits="0"/></td>
                </tr>
                <tr>
                    <td>Price</td>
                    <td>:</td>
                    <td><f:formatNumber type="currency" currencySymbol="Rp " maxFractionDigits="0" value="${prod.hargaHpp.harga * prod.weight}"/></td>
                </tr>
            </table>
        </td>
    </tr>
    <tr><td><b>Product Material</b></td></tr>
    <tr>
        <td><html:link action="/product_addmaterial.do?id=${prod.id}">Add Material</html:link></td>
    </tr>
    <tr>
        <td>
            <table>
                <tr class="table_header">
                    <th>No.</th>
                    <th>Code</th>
                    <th>Name</th>
                    <th>Weight</th>
                    <th>Quantity</th>
                    <th>Action</th>
                </tr>
                <c:set var="x" value="0"/>
                <c:forEach items="${prod.produkMaterials}" var="m">
                    <tr>
                        <td>${x+1}.</td>
                        <td>${m.material.kode}</td>
                        <td>${m.material.nama}</td>
                        <td>${m.material.weight}</td>
                        <td>${m.jumlah}</td>
                        <td>
                            <html:link action="/product_preupdatematerial.do?id=${x}">Edit</html:link> |
                            <html:link action="/product_deletematerial.do?id=${x}">Remove</html:link>
                        </td>
                    </tr>
                    <c:set var="x" value="${x+1}"/>
                </c:forEach>
                <c:if test="${x==0}">
                    <tr><td colspan="6">Product have no material.</td></tr>
                </c:if>
                    <tr class="table_header"><th colspan="6">New material that you request to add.</th></tr>
                <c:set var="x" value="0"/>
                <c:forEach items="${listMaterial}" var="m">
                    <tr>
                        <td>${x+1}.</td>
                        <td>${m.material.kode}</td>
                        <td>${m.material.nama}</td>
                        <td>${m.material.weight}</td>
                        <td>${m.jumlah}</td>
                        <td>
                            <html:link action="/product_preupdatematerial.do?id=${x}&scope=session">Edit</html:link> |
                            <html:link action="/product_removematerial.do?id=${x}">Remove</html:link>
                        </td>
                    </tr>
                    <c:set var="x" value="${x+1}"/>
                </c:forEach>
                <c:if test="${x==0}">
                    <tr><td colspan="6">Product have no requested material.</td></tr>
                </c:if>
                <c:if test="${x!=0}">
                    <tr><td colspan="6"><html:link action="/product_savematerial.do">Save requested Material</html:link></td></tr>
                </c:if>
                <tr class="table_footer">
                    <td colspan="10">PT. Dhemar Nusantara - PT. Rahmi Ida Nusantara</td>
                </tr>
            </table>
        </td>
    </tr>
</table>